package com.k12.admim.utils;

import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

public class RequestContextUtil {

    private static final String TENANT_HEADER = "X-Tenant-ID";

    /**
     * 获取request
     * @return
     */
    public static HttpServletRequest getCurrentRequest() {
        ServletRequestAttributes attributes = (ServletRequestAttributes)
                RequestContextHolder.getRequestAttributes();
        if (attributes != null) {
            return attributes.getRequest();
        }
        return null;
    }

    public static String getTenantId() {
        HttpServletRequest request = getCurrentRequest();
        if (request != null) {
            return request.getHeader(TENANT_HEADER);
        }
        return null;
    }
}
